package com.ruoyi.web.controller.chargeback.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.charge.bo.PriceAddBo;
import com.ruoyi.charge.bo.PriceEditBo;
import com.ruoyi.charge.bo.PriceQueryBo;
import com.ruoyi.charge.service.IPriceService;
import com.ruoyi.charge.vo.PriceVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 充电价格Controller
 * 
 * @author fanqie
 * @date 2021-12-02
 */
@Api(value = "后台充电价格控制器", tags = {"后台充电价格管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/back/price")
public class BackPriceController extends BaseController {

    private final IPriceService iPriceService;

    /**
     * 查询充电价格列表
     */
    @ApiOperation("查询充电价格列表")
    @PreAuthorize("@ss.hasPermi('back:price:list')")
    @GetMapping("/list")
    public TableDataInfo<PriceVo> list(PriceQueryBo bo) {
        startPage();
        List<PriceVo> list = iPriceService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出充电价格列表
     */
    @ApiOperation("导出充电价格列表")
    @PreAuthorize("@ss.hasPermi('back:price:export')")
    @Log(title = "充电价格", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<PriceVo> export(PriceQueryBo bo) {
        List<PriceVo> list = iPriceService.queryList(bo);
        ExcelUtil<PriceVo> util = new ExcelUtil<PriceVo>(PriceVo.class);
        return util.exportExcel(list, "充电价格");
    }

    /**
     * 获取充电价格详细信息
     */
    @ApiOperation("获取充电价格详细信息")
    @PreAuthorize("@ss.hasPermi('back:price:query')")
    @GetMapping("/{id}")
    public AjaxResult<PriceVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iPriceService.queryById(id));
    }

    /**
     * 新增充电价格
     */
    @ApiOperation("新增充电价格")
    @PreAuthorize("@ss.hasPermi('back:price:add')")
    @Log(title = "充电价格", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody PriceAddBo bo) {
        return toAjax(iPriceService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改充电价格
     */
    @ApiOperation("修改充电价格")
    @PreAuthorize("@ss.hasPermi('back:price:edit')")
    @Log(title = "充电价格", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody PriceEditBo bo) {
        return toAjax(iPriceService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除充电价格
     */
    @ApiOperation("删除充电价格")
    @PreAuthorize("@ss.hasPermi('back:price:remove')")
    @Log(title = "充电价格" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iPriceService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
